package com.springboot.controller;

import com.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/user")
public class UserController {


    @RequestMapping("login")
    @ResponseBody
    public String login(HttpServletRequest request, HttpServletResponse response){
        User user = new User();
        user.setId(1001);
        user.setName("张三");
        request.getSession().setAttribute("user", user);
        return "login success";
    }

    /**
     * 登录后访问
     */
    @RequestMapping("center")
    @ResponseBody
    public String center(HttpServletRequest request, HttpServletResponse response){
        return "center";
    }

    /**
     * 不登录也可访问
     */
    @RequestMapping("out")
    @ResponseBody
    public String out(HttpServletRequest request, HttpServletResponse response){
        return "out";
    }

    /**
     * 未登录访问跳转
     */
    @RequestMapping("error")
    @ResponseBody
    public String error(HttpServletRequest request, HttpServletResponse response){
        return "error";
    }

}
